package com.bjsxt.Generic;

class Generic <T>{
    private T flag;

    public T getFlag() {
        return flag;
    }

    public void setFlag(T flag) {
        this.flag = flag;
    }
}


class ShowMsg{
    public void showFlag(Generic<?> generic){
        System.out.println(generic.getFlag());

    }
}
class ShowMsg1{  //通配符的上限限定，适用于泛型类，只能是子类或当前类
    public void showFlag(Generic<? extends Number> generic){
        System.out.println(generic.getFlag());
    }
}
class ShowMsg2{  //通配符的下限限定，不适用于泛型类，只能是父类或当前类
    public void showFlag(Generic<? super Number> generic){
        System.out.println(generic.getFlag());
    }
}


class Test{
    public static void main(String[] args) {
        Generic<String> generic = new Generic<>();
        generic.setFlag("admin");
        String flag  = generic.getFlag();
        System.out.println(flag);

        Generic<Integer> generic1 = new Generic<>();
        generic1.setFlag(234);
        Integer flag1  = generic1.getFlag();
        System.out.println(flag1);

        ShowMsg showMsg =new ShowMsg();
        Generic<Integer> generic2 =new Generic<>();
        generic2.setFlag(20);
        showMsg.showFlag(generic2);

        ShowMsg showMsg3 =new ShowMsg();
        Generic<String> generic3 =new Generic<>();
        generic3.setFlag("dtf");
        showMsg3.showFlag(generic3);


    }
}